package com.bigdata.sparkHive;

import org.apache.spark.sql.Dataset;
import org.apache.spark.sql.Row;
import org.apache.spark.sql.SparkSession;

/**
 * description
 *
 * @author Cyber
 * <p> Created By 2025/3/16
 * @version 1.0
 */
public class sparksql {

    public static void main(String[] args) {
        SparkSession spark = SparkSession.builder()
                .appName("SparkSQL-Hive Example")
                .master("local[*]")
                .enableHiveSupport() //启用hive支持
                .config("hive.metastore.uris", "thrift://master:9083")
                .config("spark.sql.warehouse.dir", "hdfs://master:9000/user/hive/warehouse/mycatalog")
//                .config("hive.metastore.warehouse.dir", "hdfs://master:9000/user/hive/warehouse")
//                .config("spark.sql.hive.metastore.jars", "/Users/lifangyu/soft/apache-hive-3.1.3-bin/lib")

                .config("spark.sql.catalog.mycatalog", "org.apache.spark.sql.hive.HiveCatalog") // 自定义 Catalog
                .config("spark.sql.catalog.mycatalog.uri", "thrift://master:9083") // 指向 mycatalog
                .config("hive.metastore.catalog.default", "mycatalog")
                .getOrCreate();

        Dataset<Row> hiveTable = spark.sql("show databases ;");
        hiveTable.show();
        spark.close();
        spark.stop();
    }
}
